(require (planet schematics/schemeunit:3))

(define (double x)
  (* x 2))

(define (even? n)
  (= (remainder n 2) 0))

(define (halve x)
  (/ x 2))

(define (fast-mult b n)
  (fast-mult-iter 0 b n))

(define (fast-mult-iter a b n)
  (cond ((= n 0) a)
        ((even? n) (fast-mult-iter a (double b) (halve n)))
        (else (fast-mult-iter (+ b a) (double b) (halve (- n 1))))))

(check-equal? (fast-mult 3 5) (* 3 5))
(check-equal? (fast-mult 385204 2854672) (* 385204 2854672))
